package com.mxpio.erp.plm.service.impl;

import com.mxpio.erp.common.enums.PlmEnums;
import com.mxpio.erp.common.plm.entity.ProjectDanger;
import com.mxpio.erp.common.plm.entity.ProjectInfo;
import com.mxpio.erp.common.plm.service.ProjectDangerService;
import com.mxpio.erp.common.plm.service.ProjectInfoService;
import com.mxpioframework.common.exception.MBootException;
import com.mxpioframework.security.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

/**
 * 项目风险列表接口
 * @author qb
 * @date 2024-2-21
 */
@Service
public class ProjectDangerServiceImpl extends BaseServiceImpl<ProjectDanger> implements ProjectDangerService {

    @Autowired
    private ProjectInfoService projectInfoService;
    /**
     * 审核问题风险
     * @param projectDanger
     */
    @Override
    @Transactional
    public void audit(ProjectDanger projectDanger) {
        ProjectDanger byId = this.getById(ProjectDanger.class, projectDanger.getDangerCode());
        ProjectInfo projectInfo = projectInfoService.getById(ProjectInfo.class, projectDanger.getProCode());
        if (byId == null || projectInfo == null){
            throw  new MBootException("项目风险或项目信息不存在");
        }
        byId.setProcessing(projectDanger.getProcessing());
        byId.setProcessingDesc(projectDanger.getProcessingDesc());
        byId.setDangerStatus(PlmEnums.DangerStatus.FINISH.getCode());
        this.update(byId);
    }


}
